<template>
  <div class="cloud_system">
    <div class="desk_info">
      <el-card class="box-card">
        <template #header>
          <div class="card-header">
            <span>文件操作</span>
          </div>
        </template>
        <div class="icon_box">
          <div class="icon"></div>
        </div>
        <div class="font">
          <el-icon><lightning /></el-icon>云桌面
        </div>
        <el-divider>
          <el-icon><star-filled /></el-icon>
        </el-divider>
        <el-collapse>
          <el-collapse-item title="文件下载" name="3">
            <el-table :data="fileList" style="width: 100%">
              <el-table-column label="文件名" prop="filename" />
              <el-table-column label="大小" prop="size" />
              <el-table-column align="right">
                <template #default="scope">
                  <el-button
                    size="small"
                    @click="handleDownLoad(scope.$index, scope.row)"
                    >下载</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item title="视频列表" name="4">
            <el-table :data="List" style="width: 100%">
              <el-table-column label="视频名" prop="filename" />
              <el-table-column label="大小" prop="size" />
              <el-table-column align="right">
                <template #default="scope">
                  <el-button
                    size="small"
                    @click="handleVideo(scope.$index, scope.row)"
                    >播放</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
        </el-collapse>
      </el-card>
    </div>
    <div class="file">
      <upload-file />
    </div>
  </div>
</template>
<script setup>
import { ref } from 'vue'
import UploadFile from '@/components/UploadFile.vue'
import { getFileInfo } from '@/api/file.js'
import { ElMessage } from 'element-plus'
const fileList = ref([])
const List = ref([])
async function getFile () {
  const { data } = await getFileInfo()
  fileList.value = data.data
}
function handleDownLoad (index, row) {
  // window.open(`http://192.168.0.126:3000/downloadFile?filename=${row.filename}`)
  try {
    window.location.href = `http://192.168.0.126:3000/downloadFile?filename=${row.filename}`
    ElMessage({
      type: 'success',
      message: '下载成功'
    })
  } catch (error) {
    ElMessage({
      type: 'error',
      message: '下载失败'
    })
  }
}
function handleVideo () {}
getFile()
</script>
<style lang="less" scoped>
.cloud_system {
  flex: 1;
  display: flex;
  padding: 15px;
  .desk_info {
    width: 30%;
    height: 100%;
    margin-right: 20px;
    .el-card {
      .el-card__body {
        .el-collapse {
          height: 400px;
          overflow: auto;
          /deep/ .el-collapse-item {
            .el-collapse-item__wrap {
              .el-collapse-item__content {
                height: 200px;
                overflow: auto;
              }
            }
          }
        }
      }

      .icon_box {
        display: flex;
        justify-content: center;
        .icon {
          width: 100px;
          height: 100px;
          background-image: url("~@/assets/images/file.png");
          background-repeat: no-repeat;
          background-size: 100% 100%;
          background-position: center;
        }
      }
      .font {
        display: flex;
        align-items: center;
        margin-top: 40px;
        .el-icon {
          font-size: 20px;
        }
      }
    }
  }
  .file {
    width: 70%;
    height: 100%;
    background: floralwhite;
  }
}
</style>
